﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }

    .selectbox {
        color: #444;
        line-height: 30px;
        display: block;
        padding-left: 8px;
        padding-right: 20px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 5px;
        height: 30px;
        width: 150px;
    }

    .search table td {
        height: 30px;
        line-height: 30px;
    }

    .zdyPanel {
        height: 50px;
        line-height: 50px;
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        height: 50px;
        line-height: 50px;
        padding: 0px;
        width: 100px;
        margin: 0px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }
</style>
<script type="text/javascript">
    var resultData;
    var selectPage = -1;
    var init = -1;
    $(function () {
        getItemList();
        InitSelectControl();
        gridList();
    });

    var selectPage = -1;
    function getItemList() {
        $.ajax({
            url: "/MyTask/ReportManager/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });
    }

    function dateFtt(fmt, date) { //author: meizz
        var o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //日
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //分
            "s+": date.getSeconds(),                 //秒
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    function InitSelectControl() {
        $("#F_UserId").bindSelect({
            url: "/MyTask/ReportManager/GetUsersJson",
            search: true,
            id: "F_Id",
            text: "F_RealName",
            placeholder: '请选择销售人员'
        });

        $("#F_ClientId").bindSelect({
            url: "/MyTask/ReportManager/GetClientList",
            search: true,
            id: "F_Id",
            text: "F_ClientName",
            placeholder: '请选择客户名称'
        });
    }

    function gridList() {
        var $gridList = $("#gridList");
        var queryJson = {
            UserId: $("#F_UserId").val(),
            F_ClientId: $("#F_ClientId").val()
        };
        $gridList.dataGrid({
            url: "/MyTask/ReportManager/GetGridList",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 400,
            colModel: [
                { label: '跟进销售', name: 'F_CreatorUserId', align: 'left' },
                { label: '客户名称', name: 'F_ClientName', align: 'left' },
                { label: '活动名称', name: 'F_ActivityName', align: 'left' },
                {
                    label: '活动城市', name: 'F_CityId', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.citys.length; i++) {
                            if (resultData.citys[i]["F_ItemCode"] == rowObject["F_CityId"]) {
                                return resultData.citys[i]["F_ItemName"];
                            }
                        }
                    }
                },
                {
                    label: '活动进场时间', name: 'F_InStartTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '活动开始时间', name: 'F_StartTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '活动结束时间', name: 'F_EndTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '所属行业', name: 'F_ActivityIndustry', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.sshy.length; i++) {
                            if (resultData.sshy[i]["F_ItemCode"] == rowObject["F_ActivityIndustry"]) {
                                return resultData.sshy[i]["F_ItemName"];
                            }
                        }
                    }
                },
                {
                    label: '活动类型', name: 'F_ActivityType', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.activityType.length; i++) {
                            if (resultData.activityType[i]["F_ItemCode"] == rowObject["F_ActivityType"]) {
                                return resultData.activityType[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '预算金额', name: 'F_BudgetCash', align: 'left' },
                {
                    label: '活动阶段', name: 'F_ActivityStep', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.hdjd.length; i++) {
                            if (resultData.hdjd[i]["F_ItemCode"] == rowObject["F_ActivityStep"]) {
                                return resultData.hdjd[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '品牌', name: 'F_Brand', align: 'left' },
                {
                    label: '场地类型', name: 'F_SiteType', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.SiteType.length; i++) {
                            if (resultData.SiteType[i]["F_ItemCode"] == rowObject["F_SiteType"]) {
                                return resultData.SiteType[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '场地大小', name: 'F_SiteSize', align: 'left' },
                { label: '预计人数', name: 'F_PeopleNum', align: 'left' },
                {
                    label: '配套设施', name: 'F_Companions', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var strHtml = "";
                        for (var i = 0; i < resultData.SiteSupportingFacilities.length; i++) {
                            for (var j = 0; j < rowObject["F_Companions"].split(',').length; j++) {
                                if (j == rowObject["F_Companions"].split(',').length - 1) {
                                    if (resultData.SiteSupportingFacilities[i]["F_ItemCode"] == rowObject["F_Companions"].split(',')[j]) {
                                        strHtml += resultData.SiteSupportingFacilities[i]["F_ItemName"];
                                    }
                                } else {
                                    if (resultData.SiteSupportingFacilities[i]["F_ItemCode"] == rowObject["F_Companions"].split(',')[j]) {
                                        strHtml += resultData.SiteSupportingFacilities[i]["F_ItemName"] + ",";
                                    }
                                }
                            }
                        }
                        return strHtml;
                    }
                },
                { label: '创建时间', name: 'F_CreatorTime', align: 'left' },
                { label: '', name: 'F_Id', hidden: true },
                { label: '', name: 'F_ClientId', hidden: true },

            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_ClientId',
            ondblClickRow: function (rowid, iRow, iCol, e) {
                selectPage = rowid;
                reloadGridListRecord(iRow["F_ClientId"]);                
            },
            loadComplete: function (data) {                
                if (init == -1) {
                    gridListRecord(0);
                } else {
                    if (data.rows.length > 0) {
                        reloadGridListRecord(data.rows[0].F_ClientId);
                    } else {
                        reloadGridListRecord(0);
                    }                        
                }               
            }
        });
    }

    function reloadGridListRecord(F_ClientId) {       
        var queryJson = {
            F_ClientId: F_ClientId
        };        
        var $gridListRecord = $("#gridListRecord");
        $gridListRecord.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function gridListRecord(pageindex) {
        var $gridListRecord = $("#gridListRecord");
        var rowobj = $("#gridList").jqGridRowValue()[pageindex];
        var queryJson = {
            F_ClientId: rowobj == undefined ? "" : rowobj["F_ClientId"]
        };
        $gridListRecord.dataGrid({
            url: "/MyTask/ReportManager/GetGridDetailList",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 200,
            colModel: [
                { label: '客户名称', name: 'F_ClientId', align: 'left' },
                { label: '对接人', name: 'F_DockingName', align: 'left' },
                { label: '手机号码', name: 'F_Phone', align: 'left' },
                {
                    label: '公司职位', name: 'F_PositionId', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.gszw.length; i++) {
                            if (resultData.gszw[i]["F_ItemCode"] == rowObject["F_PositionId"]) {
                                return resultData.gszw[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '目标', name: 'F_Target', align: 'left' },
                { label: '行动计划', name: 'F_Action', align: 'left' },
                {
                    label: '行动日期', name: 'F_ActionDate', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '工作进度', name: 'F_Progress', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.hdjd.length; i++) {
                            if (resultData.hdjd[i]["F_ItemCode"] == rowObject["F_Progress"]) {
                                return resultData.hdjd[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '指标备注', name: 'F_IndexRemark', align: 'left' },
                { label: '创建时间', name: 'F_CreatorTime', align: 'left' },
                { label: '', name: 'F_Id', hidden: true },
            ],
            pager: "#gridPagerRecord",
            viewrecords: true,
        });
    }

    function btnSearch() {
        var $gridList = $("#gridList");
        var queryJson = {
            UserId: $("#F_UserId").val(),
            F_ClientId: $("#F_ClientId").val()
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
        selectPage = -1;
        init = 0;      
    }
</script>
<div class="zdyContentPanel" style="height:25px;line-height:25px;background-color:#eee;border:1px solid #ddd;margin-bottom:2px;">
    <span class="zdyFont">操作说明：上下表格行数据联动，请双击！</span>
</div>
<div class="zdyPanel">
    <div class="zdyTool">
        <div class="zdyBar" style="float:left;white-space:nowrap;width:800px;margin-top:5px;">
            <div class="search">
                <table class="form" style="width:600px;">
                    <tr>
                        <td class="formValue">
                            <select id="F_UserId" name="F_UserId" class="selectbox">
                                <option value="">==请选择销售人员==</option>
                            </select>
                        </td>
                        <td class="formValue">
                            <select id="F_ClientId" name="F_ClientId" class="selectbox">
                                <option value="">==请选择客户名称==</option>
                            </select>
                        </td>                        
                        <td>
                            <div class="input-group">
                                <button id="btn_search" onclick="btnSearch()" type="button" class="btn  btn-primary" style="padding:5px 20px">按条件筛选</button>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="zdyBar" style="float:right;white-space:nowrap;width:80px;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
        </div>
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<div class="zdyContentPanel">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#visitRecord" data-toggle="tab">拜访记录表</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane fade in active" id="visitRecord">          
            <div class="zdyGirdPanel">
                <table id="gridListRecord"></table>
                <div id="gridPagerRecord"></div>
            </div>
        </div>       
    </div>
</div>
